package com.easylinkin.linkappapi.lobar.controller.app;

import com.easylinkin.linkappapi.lobar.dto.UserGateDTO;
import com.easylinkin.linkappapi.lobar.dto.app.AppUserGateDTO;
import com.easylinkin.linkappapi.lobar.service.UserGateService;
import io.swagger.annotations.Api;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: app端健康管理
 */
@RestController
@RequestMapping("appUserGate")
@Api(tags = "app端健康管理")
public class AppUserGateController {

  @Autowired
  private UserGateService userGateService;

  /**
   *app健康管理首页统计
   */
  @GetMapping("index")
  public RestMessage countSum(String time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    AppUserGateDTO appUserGateDTO = userGateService.countSum(date);
    return RestBuilders.successBuilder().data(appUserGateDTO).build();
  }

  /**
   *app参建单位统计
   */
  @GetMapping("company")
  public RestMessage getCompany(String time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    List<AppUserGateDTO> appUserGateDTOS = userGateService.getCompany(date);
    return RestBuilders.successBuilder().data(appUserGateDTOS).build();
  }

  /**
   *app班组统计
   */
  @GetMapping("group/{companyProjectId}")
  public RestMessage getGroup(@PathVariable("companyProjectId")String companyProjectId, String time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    List<AppUserGateDTO> appUserGateDTOS = userGateService.getGroup(companyProjectId,date);
    return RestBuilders.successBuilder().data(appUserGateDTOS).build();
  }

  /**
   *app人员统计
   */
  @GetMapping("user")
  public RestMessage getUser(String companyProjectId,String groupId, String time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    List<UserGateDTO> userGates = userGateService.getUser(companyProjectId,groupId,date);
    return RestBuilders.successBuilder().data(userGates).build();
  }
}
